#include "StdAfx.h"
#include "ControlContainer.h"


CControlContainer::~CControlContainer(void)
{
}
void CControlContainer::AddControl(CControl* pCtrl)
{
	m_mChildCtrls.insert(std::make_pair(pCtrl->GetName(), m_vChildCtrls.insert(m_vChildCtrls.end(), pCtrl)));
}
void CControlContainer::RemoveControl(LPCTSTR szName)
{
	auto iter = m_mChildCtrls.find(szName);
	if (iter != m_mChildCtrls.end())
	{
		m_vChildCtrls.erase(iter->second);
		m_mChildCtrls.erase(iter);
	}
}
void CControlContainer::RemoveAllControls(void)
{
	m_vChildCtrls.clear();
	m_mChildCtrls.clear();
}


CPanel::CPanel(LPCTSTR szName, CControl* pParent)
	: CControl(szName, pParent)
{
}
CPanel::~CPanel(void)
{
}
void CPanel::_UpdateLayout(void)
{
	std::for_each(m_vChildCtrls.begin(), m_vChildCtrls.end(), 
	[&](CControl* pChildCtrl)
	{
		pChildCtrl->Update();
	});

	this->OnPaint(this, m_pAppearance->GetClientAreaBounds());
}
void CPanel::_PaintClientArea(const Rect& rcPaint)
{
	std::for_each(m_vChildCtrls.begin(), m_vChildCtrls.end(), 
	[&](CControl* pChildCtrl)
	{
		pChildCtrl->ImmediDraw(rcPaint);
	});

	this->OnPaint(this, rcPaint);
}
CAppearance* CPanel::_CreateAppearance(const Jin::CProperties& prop)
{
	return CAppearance::CreateAppearance(_T("BasicAppearance"), prop);
}


